package io.github.consoles.dsa;

import java.io.File;

/**
 * Created by yiihua-013 on 17/6/15.
 */
public class FileWorker {

    String getIndent(int depth) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < depth; i++) sb.append("--");
        return sb.toString();
    }

    void listFile(File dirname, int depth, LinkedQueue<String> queue) {

        if (dirname.isFile()) {
            String filename = getIndent(depth) + "*" + dirname.getName();
            queue.enqueue(filename);
        } else if (dirname.isDirectory()) {
            String filename = getIndent(depth) + dirname.getName();
            queue.enqueue(filename);
            File[] files    = dirname.listFiles();
            depth++;
            for (File file : files) {
                listFile(file, depth, queue);
            }
        }
    }
}
